package com.feihua.starter.service.impl;

import com.feihua.starter.service.api.ApiHdbArticlePoService;
import com.feihua.starter.service.api.ApiHdbImagePoService;
import com.feihua.starter.service.modules.hdb.dto.HdbArticleDto;
import com.feihua.starter.service.modules.hdb.po.HdbArticlePo;
import com.github.pagehelper.Page;
import feihua.jdbc.api.pojo.PageResultDto;
import feihua.jdbc.api.service.impl.ApiBaseServiceImpl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * This class was generated by MyBatis Generator.
 *
 * @author revolver 2018-08-30 14:05:19
 */
@Service
public class ApiHdbArticlePoServiceImpl extends ApiBaseServiceImpl<HdbArticlePo, HdbArticleDto, String> implements ApiHdbArticlePoService {
    @Autowired
    com.feihua.starter.service.mapper.HdbArticlePoMapper HdbArticlePoMapper;
    @Autowired
    private ApiHdbImagePoService apiHdbImagePoService;

    public ApiHdbArticlePoServiceImpl() {
        super(HdbArticleDto.class);
    }

    @Override
    public HdbArticleDto addOrUpdate(HdbArticleDto dto) throws Exception {
        HdbArticlePo po = new HdbArticlePo();
        BeanUtils.copyProperties(dto, po);
        if (dto.getId() == null) {
            super.preInsert(po, dto.getCreateBy());
            HdbArticleDto hdbArticleDto = super.insert(po);
            dto.setId(hdbArticleDto.getId());
        } else {
            super.preUpdate(po, dto.getUpdateBy());
            super.updateByPrimaryKeySelective(po);
        }

        apiHdbImagePoService.addOrUpdate(dto.getHdbImages(), dto.getId(), dto.getCreateBy());

        return dto;
    }
}